<?php
include_once '../action/pegawaiController.php';
include 'z_header.php';
if(!isset($_SESSION['nip'])){
    header('location:login.php');
}
//AWAL HALAMAN LIHAT PEGAWAI
if(isset($_GET['view'])){
?>
<div class="container-fluid">  
<div class="row-fluid">
<?php     
if(isset($berhasil_hapus))
        {
                echo '<div class="alert alert-success" id="alert">'.$berhasil_hapus.'
                      <button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
        }
 ?>
<div class="accordion-group">
<table class="table table-striped table-bordered" id="tabel_pegawai">  
    <fieldset>  
        <legend><div class="pull-left">&nbsp;Daftar Pegawai</div>
            <?php if($_SESSION['admin']=="Y"){ ?>
            <div class="pull-right"><a href="modul.pegawai.php?rekam" class="btn btn-primary">Rekam Pegawai Baru</a>&nbsp;</div> <?php } ?>
         </legend>  
        <thead>  
          <tr>  
            <th width="250">Pegawai</th>   
            <th width="200">Jenis Kelamin</th>
            <th width="200">Status Kawin</th>
            <th width="250">Pangkat/Golongan</th>  
            <th width="300">Seksi</th>
            <?php if($_SESSION['admin']=='Y'){ ?>
            <th width="100">Status</th> 
            <th width="200">Aksi</th>
            <?php } ?>
          </tr>  
        </thead>  
        <tbody> 
            <?php 
            if($data!=NULL){
                foreach ($data as $peg){
                    $kawin=explode(",",$peg->status_kawin);
            ?>
          <tr>  
            <td><?php echo $peg->nama_pegawai; ?> <br>
                <?php echo $peg->nip; ?><br>    
            </td> 
            <td><?php echo $peg->jns_kelamin;?></td> 
            <td><?php echo $kawin[0].'<br>'.$kawin[1];?></td> 
            <td><?php echo $peg->pangkat_golongan; ?></td>
            <td><?php echo $peg->seksi; ?></td> 
            <?php if($_SESSION['admin']=='Y'){ ?>
            <td><?php echo '<strong>'.$peg->status.'</strong>'; ?></td>
            <td><a href="?ubah&id=<?php echo $peg->nip;?>" <button class="btn btn-warning"><i class="icon-edit"></i>Ubah</button></a>
                <?php if($peg->status=='Non Aktif'){?>
                 <a href="?hapus&nip=<?php echo $peg->nip;?>" data-confirm="Anda Yakin Akan menghapus pegawai NIP: <?php echo $peg->nip; ?> ?" <button class="btn btn-danger"><i class="icon-remove"></i>Hapus</button></a>
                     </a>

                  <?php  } ?>
            </td>
            <?php } ?>
            
          </tr> 
          <?php
                }
            }?>   
        </tbody>  
        </fieldset>
      </table>
<div class="pagination pagination-mini">
    &nbsp;
                <ul>
                <?php
                        $index=1;
                        if(isset($_GET['hal']))
                        {
                                $selected=$_GET['hal'];
                        }else
                        {
                                $selected=1;
                        }
                       
                        if(isset($_GET['hal']) && $_GET['hal']!=1)
                        {
                                $prev=$_GET['hal']-1;
                                echo '<li class=""><a href="modul.pegawai.php?view&hal='.$prev.'">Prev</a></a></li>';                              
                        }
                        elseif(isset($_GET['hal']) && ($_GET['hal'])==1)
                        {
                                echo '<li class="disabled"><a href="modul.pegawai.php?view&hal=1">Prev</a></a></li>';
                        }                      
                        else
                        {
                                echo '<li class="disabled"><a href="modul.pegawai.php?view&hal=1">Prev</a></a></li>';
                        }
                       
                        for($i=1;$i<=$jml_hal;$i++)
                        {      
                                if($selected==$i)
                                {
                                        echo '<li class="active"><a href="modul.pegawai.php?view&hal='.$i.'">'.$index.'</a></li>';
                                }
                                else
                                {
                                        echo '<li class=""><a href="modul.pegawai.php?view&hal='.$i.'">'.$index.'</a></li>';
                                }
                                $index++;
                        }      

                        if(isset($_GET['hal']) && ($jml_hal)!=$_GET['hal'])
                        {
                                $next=$_GET['hal']+1;
                                echo '<li class=""><a href="modul.pegawai.php?view&hal='.$next.'">Next</a></a></li>';                              
                        }
                        elseif(isset($_GET['hal']) && ($jml_hal)==$_GET['hal'])
                        {
                                $next=$_GET['hal'];
                                echo '<li class="disabled"><a href="modul.pegawai.php?view&hal='.$next.'">Next</a></a></li>';
                        }
                        elseif($jml_hal==1)
                        {
                                echo '<li class="disabled"><a href="modul.pegawai.php?view&hal=1">Next</a></a></li>';
                        }
                        elseif(!isset($_GET['hal']))  
                        {
                                $next=1;
                                echo '<li class=""><a href="modul.pegawai.php?view&hal='.$next.'">Next</a></a></li>';
                        }                      
                        else
                        {
                                $next=$_GET['hal']+1;
                                echo '<li class=""><a href="modul.pegawai.php?view&hal='.$next.'">Next</a></a></li>';
                        }
                ?>
                </ul>
        </div> 
</div>
<?php 
include_once 'z_footer.php';
}
 

//AWAL HALAMAN REKAM PEGAWAI BARU
elseif(isset($_GET['rekam']) AND $_SESSION['admin']=="Y"){
if(isset($error_rekam))
        {
                echo '<div class="alert alert-error" id="alert">'.$error_rekam.'
                      <button type="button" class="close" data-dismiss="alert" id="close">×</button></div>';
        }
?>
<div class="container">  
<div class="row">
<div class="span9 offset1 accordion-group">
    <form class="form-horizontal" method="post" action="">  
        <fieldset>  
            <legend>&nbsp &nbsp;REKAM PEGAWAI</legend> 
            <div class="span8">
            <div class="control-group">  
                <label class="control-label" for="nip">N I P</label>  
                    <div class="controls">  
                        <input type="text" class="input-medium" name="nip" id="nip">
                    </div>  
            </div> 
            
            <div class="control-group">  
                  <label class="control-label" for="nama_pegawai">Nama Pegawai</label>  
                      <div class="controls">   
                          <input type="text" class="input-xlarge" name="nama_pegawai" id="nama_pegawai">    
                      </div>  
            </div>
            
            <div class="control-group">  
                <label class="control-label" for="pass">Password</label>  
                    <div class="controls">  
                        <input type="password" class="input-medium" name="pass" id="pass">
                    </div>  
            </div> 
            
            <div class="control-group">  
                <label class="control-label" for="kpass">Konfirmasi Password</label>  
                    <div class="controls">  
                        <input type="password" class="input-medium" name="kpass" id="kpass">
                    </div>  
            </div> 
            
            <div class="control-group">
                <label class="control-label" for="jns_kelamin">Jenis Kelamin</label>
                        <div class="controls">
                            <select name="jns_kelamin" class="input-xlarge">
                                <option value="L">Laki-laki</option>
                                <option value="P">Perempuan</option>
                            </select>
                        </div>
            </div>
            
             <div class="control-group">
                <label class="control-label" for="pangkat">Pangkat/Golongan</label>
                        <div class="controls">
                            <select name="pangkat" class="input-xlarge">
                                    <?php
                                        foreach($datapangkat as $pangkat){
                                            $pangkat2=explode(",",$pangkat->pangkat_golongan);
                                            echo "<option value=\"".$pangkat2[0]."\">".$pangkat2[1]."</option>";
                                        }
                                        ?>
                            </select>
                        </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="seksi">Seksi/Bagian</label>
                        <div class="controls">
                            <select name="seksi" class="input-xlarge">
                                    <?php
                                        foreach($dataseksi as $seksis){
                                            $seksi2=explode(",",$seksis->seksi);
                                            echo "<option value=\"".$seksi2[0]."\">".$seksi2[1]."</option>";
                                        }
                                        ?>
                            </select>
                        </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="statuskawin">Status Kawin</label>
                        <div class="controls">
                            <select name="statuskawin" class="input-xlarge">
                                    <?php
                                        foreach($datakawin as $kawinnya){
                                            $kawin=explode(",",$kawinnya->status_kawin);
                                            echo "<option value=\"".$kawin[0]."\">".$kawin[1]."</option>";
                                        }
                                        ?>
                            </select>
                        </div>
            </div>

            <div class="form-actions"> 
                <button type="button" onclick="window.self.history.back()">Batal</button>
                <button type="submit" class="btn btn-primary" name="simpan_pgw_rekam">Simpan</button>  
            </div> 
            </div>
        </fieldset>  
    </form>  
</div>
<?php 
include_once 'z_footer.php';
}
//AWAL HALAMAN UBAH PEGAWAI
elseif(isset($_GET['ubah']) AND $_SESSION['admin']=="Y"){ ?>
<div class="container">  
<div class="row">
<div class="span9 offset1 accordion-group">
    <form class="form-horizontal" method="post" action="">  
        <fieldset>  
            <legend>&nbsp &nbsp;UBAH PEGAWAI</legend>  
            <?php
//            var_dump($dataubah);
            foreach($dataubah as $ubah){
            ?>
            <div class="span8">
            <div class="control-group">  
                <label class="control-label" for="nip">N I P</label>  
                    <div class="controls">  
                        <input type="text" class="input-medium" name="nip" id="nip" value="<?php echo $ubah->nip ;?>">
                    </div>  
            </div> 
            
            <div class="control-group">  
                  <label class="control-label" for="nama_pegawai">Nama Pegawai</label>  
                      <div class="controls">   
                          <input type="text" class="input-xlarge" name="nama_pegawai" id="nama_pegawai" value="<?php echo $ubah->nama_pegawai ;?>">    
                      </div>  
            </div>
            
            <?php
                                                    foreach($data_role as $rolenya){
                                                        $roles=explode(",",$rolenya->role);
                                                        if($_SESSION['pejabat']==$roles[0]){
                                                            echo "<option value=\"".$roles[0]."\" selected>".$roles[1]."</option>";
                                                        }else{
                                                            echo "<option value=\"".$roles[0]."\">".$roles[1]."</option>";
                                                        }
                                                    }
                                                ?>
            
            <div class="control-group">
                <label class="control-label" for="jns_kelamin">Jenis Kelamin</label>
                        <div class="controls">
                            <select name="jns_kelamin" class="input-xlarge">
                               <?php
                                    foreach($datagender as $gendernya){
                                        $gender=explode(",",$gendernya->jns_kelamin);
                                        if($ubah->jns_kelamin==$gender[0]){
                                            echo "<option value=\"".$gender[0]."\" selected>".$gender[1]."</option>";
                                        }else{
                                            echo "<option value=\"".$gender[0]."\">".$gender[1]."</option>";
                                        }
                                    }
                                ?>
                            </select>
                        </div>
            </div>
            
             <div class="control-group">
                <label class="control-label" for="pangkat">Pangkat/Golongan</label>
                        <div class="controls">
                            
                            <select name="pangkat" class="input-xlarge">
                                <?php
                                    foreach($datapangkat as $pangkatnya){
                                        $pangkat=explode(",",$pangkatnya->pangkat_golongan);
                                        if($ubah->pangkat_golongan==$pangkat[0]){
                                            echo "<option value=\"".$pangkat[0]."\" selected>".$pangkat[1]."</option>";
                                        }else{
                                            echo "<option value=\"".$pangkat[0]."\">".$pangkat[1]."</option>";
                                        }
                                    }
                                ?>
                            </select>
                        </div>
             </div>
            
            
            <div class="control-group">
                <label class="control-label" for="seksi">Seksi/Bagian</label>
                        <div class="controls">
                            <select name="seksi" class="input-xlarge">
                                <?php
                                    foreach($dataseksi as $seksinya){
                                        $seksi=explode(",",$seksinya->seksi);
                                        if($ubah->seksi==$seksi[0]){
                                            echo "<option value=\"".$seksi[0]."\" selected>".$seksi[1]."</option>";
                                        }else{
                                            echo "<option value=\"".$seksi[0]."\">".$seksi[1]."</option>";
                                        }
                                    }
                                ?>
                            </select>
                        </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="statuskawin">Status Kawin</label>
                        <div class="controls">
                            <select name="statuskawin" class="input-xlarge">
                                <?php
                                    foreach($datakawin as $kawinnya){
                                        $kawin=explode(",",$kawinnya->status_kawin);
                                        if($ubah->status_kawin==$kawin[0]){
                                            echo "<option value=\"".$kawin[0]."\" selected>".$kawin[1]."</option>";
                                        }else{
                                            echo "<option value=\"".$kawin[0]."\">".$kawin[1]."</option>";
                                        }
                                    }
                                ?>
                            </select>
                        </div>
            </div>
            
            <div class="control-group">
                <label class="control-label" for="status">Status Pegawai</label>
                        <div class="controls">
                            <select name="status" class="input-medium">
                                <?php
                                    foreach($datastatus as $statusnya){
                                        $status=explode(",",$statusnya->status);
                                        if($ubah->status==$kawin[0]){
                                            echo "<option value=\"".$status[0]."\" selected>".$status[1]."</option>";
                                        }else{
                                            echo "<option value=\"".$status[0]."\">".$status[1]."</option>";
                                        }
                                    }
                                ?>
                            </select>
                        </div>
            </div>
           
            
            <div class="form-actions"> 
                <button type="button" class="btn btn-info"onclick="window.self.history.back()">Batal</button>
                <button type="submit" class="btn btn-primary" name="simpan_pgw_ubah">Simpan</button>  
            </div> 
            </div>
            <?php } ?>
        </fieldset>  
    </form>  
</div>
<?php 
include_once 'z_footer.php'; 
} ?>
<script type="text/javascript">
	$(document).ready(function(){
		$("#nip").focus();
                $('a[data-confirm]').click(function(ev) {
                                var href = $(this).attr('href');

                                if (!$('#dataConfirmModal').length) {
                                        $('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button><h3 id="dataConfirmLabel">Konfirmasi Peghapusan</h3></div><div class="modal-body"></div><div class="modal-footer"><button class="btn btn-primary" data-dismiss="modal" aria-hidden="true">Batal</button><a class="btn btn-danger" id="dataConfirmOK">Ya</a></div></div>');
                                }
                                $('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm'));
                                $('#dataConfirmOK').attr('href', href);
                                $('#dataConfirmModal').modal({show:true});
                                return false;
                        });
		});
         jQuery(function(){
                jQuery("#nip").validate({
                    expression: "if (VAL.length == 18 && !isNaN(VAL) && VAL) return true; else return false;",
                    message: "Masukkan NIP 18 digit dengan benar"
                });
                jQuery("#nama_pegawai").validate({
                    expression: "if (VAL) return true; else return false;",
                    message: "Nama pegawai harus diisi"
                });
                jQuery("#pass").validate({
                    expression: "if (VAL.length > 5 && VAL) return true; else return false;",
                    message: "Password minimal 6 karakter"
                });
                jQuery("#kpass").validate({
                    expression: "if ((VAL == jQuery('#pass').val()) && VAL) return true; else return false;",
                    message: "Konfirmasi password tidak sama dengan isian password"
                });

                                jQuery('.AdvancedForm').validated(function(){
                                        alert("Use this call to make AJAX submissions.");
                                });
            });
                
</script>
